package com.team.teamuserservice.controller;


import cn.hutool.core.bean.BeanUtil;
import com.team.teamuserservice.entity.dto.VehicleDTO;
import com.team.teamuserservice.entity.po.BizUserVehicle;
import com.team.teamuserservice.entity.vo.VehicleVO;
import com.team.teamuserservice.service.IBizUserVehicleService;
import com.team.teamuserservice.uitls.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户车辆信息 前端控制器
 * </p>
 *
 * @author cxs
 * @since 2025-07-09
 */
@RestController
@RequestMapping("/user/car")
@RequiredArgsConstructor
public class BizUserVehicleController {

    private final IBizUserVehicleService bizUserVehicleService;

    /**
     * 添加车辆
     */
    @PostMapping("/add")
    public Result addCar(@RequestParam("brand") String brand,
                         @RequestParam("model") String model,
                         String plateNumber, MultipartFile file,
                         @RequestParam("id") Long id) throws Exception {

        Boolean success = bizUserVehicleService.addCar(brand, model, plateNumber, file, id);
        return success ? Result.success() : Result.error("添加车辆失败");
    }

    /**
     * 查看车辆
     */
    @GetMapping("/select")
    public Result selectCars(Long id){

        //前端自己判断去
        return Result.success(bizUserVehicleService.select(id));

    }

    /**
     * 删除车辆
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteCat(@PathVariable("id") Long id){

        boolean successs = bizUserVehicleService.removeById(id);
        return successs ? Result.success() : Result.error("删除失败");

    }


}
